class Solution {
public:
    int findShortestSubArray(vector<int>& nums) {    
    
    for (int i=0;i< nums.size();i++)
    {
        int num = nums[i];
        cout << "input = "<< num <<",";
        //统计个数
        //auto iterator = num_count_map.find(num); 
        if (num_count_map.find(num) == num_count_map.end())
        {
            cout << "null,";
            num_count_map[num]=1;
            //记录第一次
            first_position_map[num] = i;
            last_position_map[num]  = i;
        }
        else
        {
            cout << "in,";
            num_count_map[num]++;
            last_position_map[num]=i;
        }
        
        //更新位置记录
        if  (num_count_map[num]>=max_count)
        {   
            max_count= num_count_map[num];
            the_max_num= num;
 
        }

        cout << "max_count = "<<max_count << ",the_max_num= "<< the_max_num <<"\r\n";

    }

 
    //look for min
    for (auto n :nums)
    {
        if (num_count_map[n] == max_count)
        {
             if (the_mincount==-1)
             {
                the_mincount =  last_position_map[n] - first_position_map[n]+1;
             }
             else
             {
                if (the_mincount > (last_position_map[n] - first_position_map[n])+1)
                {
                    the_mincount = last_position_map[n] - first_position_map[n]+1;
                }
             }
        }
    }


    return the_mincount;
    }

private:
    unordered_map<int,int> num_count_map;
    unordered_map<int,int> first_position_map;
    unordered_map<int,int> last_position_map;
    int the_max_num{-1};
    int the_mincount = -1;
    int max_count=0;
};